﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class CourseSettingBLL : CommonBLL<CourseSettingInfo, CourseSettingDAL>
    {
        //被动更新缓存策略
        private static CourseSettingInfo _cacheInfo;

        static CourseSettingBLL()
        {
            UpdateCache();
        }

        public static CourseSettingInfo Get()
        {
            return _cacheInfo;
        }

        private static void UpdateCache()
        {
            GetFromDb();
        }

        public new static bool Edit(CourseSettingInfo info)
        {
            using (var dal = new CourseSettingDAL())
            {
                var re = dal.Update(info) != null;
                if (re)
                    UpdateCache();
                return re;
            }
        }

        public static CourseSettingInfo GetFromDb()
        {
            using (var dal = new CourseSettingDAL())
            {
                var re = dal.SelectSingle(o => true);
                _cacheInfo = re;
                return re;
            }
        }

    }
}
